// LogUtil.js
import { ref } from 'vue'

// 输出 log 日志
// const logFileStr = ref('')
export const logState = {
  outputLines: ref([])
}

export function addOutputLine(data, type) {
  const lines = data.split('\n')
  lines.forEach((line) => {
    if (line.trim()) {
      logState.outputLines.value.push({
        type,
        data: line,
        timestamp: new Date().toLocaleTimeString()
      })
    }
  })

  if (logState.outputLines.value.length > 200) {
    logState.outputLines.value.splice(0, logState.outputLines.value.length - 200)
  }

  setTimeout(() => {
    const terminal = document.querySelector('.terminal-output')
    if (terminal) terminal.scrollTop = terminal.scrollHeight
  }, 10)
}

export function clearLogs() {
  logState.outputLines.value = []
}
